package com.zjeav.lingjiao.ui.home.model;

import com.zjeav.lingjiao.base.baseBean.Find;
import com.zjeav.lingjiao.base.baseBean.Result;
import com.zjeav.lingjiao.base.service.FindDetailService;
import com.zjeav.lingjiao.base.service.FindItemService;
import com.zjeav.lingjiao.base.tools.RetrofitInstance;

import io.reactivex.Observer;
import io.reactivex.android.schedulers.AndroidSchedulers;
import io.reactivex.disposables.Disposable;
import io.reactivex.schedulers.Schedulers;
import retrofit2.Retrofit;

public class GetFindDetailModel {
    //我的课程列表
    public void getFindDetail(int id, final OnDetailListener listener) {
        Retrofit retrofit = RetrofitInstance.getJsonTokenInstance();
        FindItemService service = retrofit.create(FindItemService.class);
        service.getFind(id)
                .subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe(new Observer<Result<Find>>() {
                    @Override
                    public void onSubscribe(Disposable d) {

                    }

                    @Override
                    public void onNext(Result<Find> find) {
                        listener.OnDetailSuccess(find);
                    }

                    @Override
                    public void onError(Throwable e) {
                        listener.OnError(e);
                    }

                    @Override
                    public void onComplete() {

                    }
                });

    }

    public interface OnDetailListener {
        void OnDetailSuccess(Result<Find> result);

        void OnError(Throwable throwable);
    }
}
